package Blog1;

import java.io.UnsupportedEncodingException;
import java.util.Arrays;

public class Blog11 {
    public static void main(String[] args) {
        String str = "HelloWorld";
        String ret = str.substring(5,9);
        System.out.println(ret);
    }


    // 截取内容到结尾
    public static void main15(String[] args) {
        String str  = "HelloWorld";
        String ret = str.substring(5);
        System.out.println(ret);
    }


    // 替换掉字符串中首个的内容
    public static void main14(String[] args) {
        String str = "abababcef";

        String ret = str.replaceFirst("a","A");
        System.out.println(str);
        System.out.println(ret);
    }


//    字符串中指定所有内容的替换
    public static void main13(String[] args) {
        String str = "ababcabdef";

        String ret = str.replace('a','A');
        String ret2 = str.replace("abc","ABC");

        System.out.println(ret);
        System.out.println(str);
        System.out.println(ret2);
    }

    public static void main12(String[] args) {
        String str = "ABC";
        String str2 = "abc";
        String str3 = "abcdef";
        String str4 = "cde";

        System.out.println(str.compareTo(str));
        System.out.println(str.compareTo(str2));
        System.out.println(str2.compareTo(str3));
        System.out.println(str2.compareTo(str4));

        System.out.println("A".compareTo("a"));
        System.out.println("s".compareTo("s"));
        System.out.println("梦".compareTo("想"));
    }


//    不区分大小写 的字符串之间的比较
    public static void main11(String[] args) {
        String str = "HELLO";
        String str2 = "hello";

        System.out.println(str.equalsIgnoreCase(str2));
        System.out.println("A".equalsIgnoreCase("a"));
    }

    public static void main10(String[] args) {
        String str = "HEELO";
        String str1 = "hello";
//        equals 的比较是区分大小写的
        System.out.println(str.equals(str1));
        System.out.println("A".equals("a"));
        System.out.println("a".equals("a"));
    }

    public static void main9(String[] args) {
        String str = null;
        //               equals 左边的比较对象不可以为 null
        //               equals 右边的比较对象可以为 null
        System.out.println("hello".equals(null));
    }


//    编码转换
    public static void main8(String[] args) throws UnsupportedEncodingException {
        String str = "abcdef";
        byte[] bytes = str.getBytes("utf-8");
        System.out.println(Arrays.toString(bytes));
    }


//    将字符串变为字节数组(byte)的值返回
    public static void main7(String[] args) {
        String str = "abcedf";
        byte[] bytes = str.getBytes();
        System.out.println(Arrays.toString(bytes));

    }


    public static void main6(String[] args) {
        byte[] bytes = {98,97,95,94,93};
        String str = new String(bytes,0,2);
        System.out.println(str);
    }


    public static boolean nums(String str) {
        for (int i = 0; i < str.length(); i++) {
            char val = str.charAt(i);
            if(val >= '0' && val <='9') {
                return true;
            }
        }
        return false;
    }

    public static void main5(String[] args) {
        String str = "hello";
        String str2 =  "99hello";
        System.out.println(nums(str));
        System.out.println(nums(str2));

    }

//    字符串变为数组返回
    public static void main4(String[] args) {
        String str = "hello";
        char[] val = str.toCharArray();
        System.out.println(Arrays.toString(val));
    }

//    获取字符串下标的内容
    public static void main3(String[] args) {
        String str = "hello";

        System.out.println(str.charAt(1));
        System.out.println(str.charAt(2));
        System.out.println(str.charAt(9));
    }



//    将部分字符数组的内容转化为字符串
    public static void main2(String[] args) {
        char[] val = {'h','e','l','l','o','w','o','r','l','d'};
        String str = new String(val,5,5);
        System.out.println(str);
    }


    public static void main1(String[] args) {
        // 将字符数组的内容全部转化为字符串
        char[] val = {'h','e','l','l','o'};
        String str = new String(val);
        System.out.println(str);
    }
}
